﻿using System;
using GameEngine.Model;
using GameEngine.Model.Data;
using GameEngine.View;
using GameEngine.View.Components;
using PureMVC.Interfaces;
using PureMVC.Patterns;
using System.Collections.Generic;

namespace GameEngine.Controller
{
    public class DestroyLevelCommand<MyIdType> : SimpleCommand
        where MyIdType : IComparable<MyIdType>
    {
        override public void Execute(INotification notification)
        {
            ILevelVO<MyIdType> levelVO = notification.Body as ILevelVO<MyIdType>;

            ILevelDataProxy<MyIdType> level = Facade.RetrieveProxy(ILevelDataProxyConstants<MyIdType>.CreateDataProxyName(levelVO)) as ILevelDataProxy<MyIdType>;
            
            foreach (var world in level.Worlds)
            {
                SendNotification(ApplicationFacade.DESTROYWORLD_COMMAND, world.Value.VO);
            }

            Facade.RemoveMediator(LevelMediatorConstants<MyIdType>.GetMediatorNameFromProxy(level));
            //SendNotification(ApplicationFacade.NEWLEVEL_NOTIFICATION, level);
            Facade.RemoveProxy(ILevelDataProxyConstants<MyIdType>.CreateDataProxyName(levelVO));
                
        }
    }
}
